﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Medical.Business;
using System.Data;
using System.Text;

/// <summary>
/// 站点地图
/// </summary>
public partial class SiteMap : WebPage
{
    protected int nPageIndex = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["page"] != null)
            {
                nPageIndex = Convert.ToInt32(Request.QueryString["page"]);
            }
            SetPageInfo("网站地图_" + strWebTitle, string.Empty, string.Empty);
            InitData();
        }
    }

    /// <summary>
    /// 加载数据
    /// </summary>
    protected void InitData()
    {
        StringBuilder sbSort = new StringBuilder();
        DataTable dtSort = new BisSortInfo().GetAllSortList();
        string strUrl = string.Empty;
        for (int i = 0; i < dtSort.Rows.Count; i++)
        {
            ArticelTypeEnum aType = (ArticelTypeEnum)Convert.ToInt32(dtSort.Rows[i]["Type"]);
            switch (aType)
            {
                case ArticelTypeEnum.Equipment:
                case ArticelTypeEnum.Expert:
                case ArticelTypeEnum.About:
                case ArticelTypeEnum.Subject:
                    continue;
                case ArticelTypeEnum.News:
                    if (dtSort.Rows[i]["PID"] == DBNull.Value)
                    {
                        continue;
                    }
                    break;

            }
            switch (aType)
            {
                case ArticelTypeEnum.FeedBack:
                    sbSort.Append("<a href=\"/faq/" + dtSort.Rows[i]["PageUrlName"].ToString() + "/\" title=\"" + dtSort.Rows[i]["Name"].ToString() + "\" target=\"_blank\">" + Server.HtmlEncode(dtSort.Rows[i]["Name"].ToString()) + "</a>");
                    break;
                default:
                    sbSort.Append("<a href=\"/" + (dtSort.Rows[i]["PID"].ToString() != string.Empty ? (dtSort.Rows[i]["PPageUrlName"].ToString() + "/") : "") + dtSort.Rows[i]["PageUrlName"].ToString() + "/\" title=\"" + dtSort.Rows[i]["Name"].ToString() + "\" target=\"_blank\">" + Server.HtmlEncode(dtSort.Rows[i]["Name"].ToString()) + "</a>");
                    break;
            }
        }
        sbSort.Append("<div class=\"clear\"></div>");
        sortlist.InnerHtml = sbSort.ToString();

        StringBuilder sbArticle = new StringBuilder();
        int nRecordCount = 0;
        int nPageCount = 0;
        //文章信息列表绑定
        DataTable dtArticle = new BisArticle().GetAllArticleList(string.Empty, nPageIndex, anpPage.PageSize, ref nPageCount, ref nRecordCount);
        anpPage.RecordCount = nRecordCount;
        sbArticle.Append("<ul>");
        foreach (DataRow dr in dtArticle.Rows)
        {
            if (dr["Type"] != DBNull.Value)
            {
                ArticelTypeEnum aType = (ArticelTypeEnum)Convert.ToInt32(dr["Type"]);
                switch (aType)
                {
                    case ArticelTypeEnum.Subject:
                    case ArticelTypeEnum.About:
                        continue;
                }
                sbArticle.Append("<li><span>[<a href=\"/" + (dr["PSortUrlName"].ToString() != string.Empty ? (dr["PSortUrlName"].ToString() + "/") : "") + dr["SortUrlName"].ToString() + "/\" title=\"" + dr["SortName"].ToString() + "\" target=\"_blank\">" + Server.HtmlEncode(dr["SortName"].ToString()) + "</a>]</span><a href=" + Until.GetUrlName(dr["PSortUrlName"], dr["SortUrlName"], dr["ID"]) + " title=" + dr["Name"].ToString() + " target=\"_blank\">" + Server.HtmlEncode(dr["Name"].ToString()) + "</a></li>");
            }
            else
            {
                sbArticle.Append("<li><span>[<a href=\"/faq/" + dr["SortUrlName"].ToString() + "/\" title=\"" + dr["SortName"].ToString() + "\" target=\"_blank\">" + Server.HtmlEncode(dr["SortName"].ToString()) + "</a>]</span><a href=" + Until.GetUrlName(dr["ArticleType"],dr["PSortUrlName"], dr["SortUrlName"], dr["ID"]) + " title=" + dr["Name"].ToString() + " target=\"_blank\">" + Server.HtmlEncode(dr["Name"].ToString()) + "</a></li>");
            }
        }
        sbArticle.Append("</ul>");
        articlelist.InnerHtml = sbArticle.ToString();
    }
}